#!/bin/bash

##判断是否安装了python3
python3 --version> /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
    echo "你已经装过了python3"
    exit
fi

echo "升级所有包同时也升级软件和系统内核"
yum -y update
echo "安装依赖环境"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
echo "下载Python3"
cd /opt
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
echo "安装Python3"
mkdir -p /usr/local/python3
tar -zxvf Python-3.7.1.tgz
echo "3.7版本之后需要一个新的包libffi-devel"
yum install libffi-devel -y
cd Python-3.7.1
./configure --prefix=/usr/local/python3
make && make install
echo "建立Python3和pip3的软链:"
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
echo "添加环境变量"
cat >> /etc/profile <<EOF
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
EOF
source ~/.bash_profile
echo "检查安装版本"
python3 -V
pip3 -V


